<?php

/**
 * Menu item model class
 *
 * @package
 * @subpackage
 * 
 * @author valerii lazarevych <valeriy.fremar@gmail.com>
 * @copyright fremar ltd.
 */
class Menuitems_domainObject      extends    domainObject
{
    /**
     * Menu item name
     * 
     * @var string $name
     */
    public   $name       =   null;
    
    /**
     * Online/Offline status
     * 
     * @var string $miStatus
     */
    public   $miStatus   =   null;
    
    /**
     * Menu item href link
     * 
     * @var string $link
     */
    public   $link       =   null;
    
    /**
     * Menu item order position
     * 
     * @var int $miOrder
     */
    public   $miOrder    =   null;
    
    /**
     * Menu item type
     * 
     * 0 not logged user menu
     * 1 logged user menu
     * 2 cms menu
     * 
     * @var string $cms
     */
    public   $cms        =   null;
    
    /**
     * Menu item description
     * 
     * @var string
     */
    public   $text       =   null;
    
    /**
     * Active menu item
     * 
     * Active means menu item we have clicked
     * By default active menu is the first item 
     * of the menu list
     * 
     * @var Menuitem $active
     */
    protected static   $active  =   null;
    
    /**
     * Output menu item as web link
     * 
     * @return string   | html string
     */
    public function getLink()
    {
        return  '<li><a class="" href="/'.$this->link .'">&nbsp;'.$this->name.'</a></li>';
    }
    
    /**
     * Url address validation
     * 
     * @todo  add url validation
     * 
     * @return string   | url
     */
    public function hasLink()
    {        
        return $this->link ?: null;
    }

    /**
     * Set active menu item
     * 
     * @param MenuItem $menuItem
     */
    public static function setActive(Request $request = null)
    {
        $defaultMenu   =   new self;
        $defaultMenu->find('1');
        
        $menuItem      =   '';
        
        self::$active   =   $menuItem   ?:  $defaultMenu;        
    }
    
    /**
     * Get active menu item
     * 
     * @return Menuitem
     */
    public static function getActive()
    {
        if (!self::$active){                        
             self::setActive();
        }
        return self::$active;
    }
}

?>
